home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / binary-op-and check.izs < prev    next >
Text File  |  2005-09-28  |  5KB  |  328 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Binary Operators and CheckBox
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>This script is a good example of the use of binary operations with check boxes to obtain a single number which is the binary representation of the selected check boxes. There is also a button to show you your selections in text form. <!/DESCRIPTION> 
  7.  
  8. <!CATEGORY>Forms<!/CATEGORY>
  9.  
  10. <!SCRIPT>
  11. <!-- START OF SCRIPT -->
  12.  
  13. <!-- HOW TO INSTALL BINARY OPERATORS AND CHECKBOX:
  14.  
  15.  
  16.  
  17.   1.  Copy code into the body section of document  -->
  18.  
  19.  
  20.  
  21. <!-- STEP ONE: Add this code into BODY section of document  -->
  22.  
  23.  
  24.  
  25. <BODY>
  26.  
  27.  
  28. <!-- Original:  Victor Cuervo (victor@aulambra.com ) -->
  29.  
  30. <!-- Web Site:  http://www.aulambra.com -->
  31.  
  32.             <table border="1" width="100%" cellpadding="10" cellspacing="0" bordercolor="#000000" bordercolordark="#000000" bordercolorlight="#000000" height="339">
  33.  
  34.               <tr>
  35.  
  36.                 <td width="100%" height="297" valign="top"> 
  37.  
  38.                   
  39.  
  40. <script>
  41.  
  42.  
  43.  
  44. datos = ['Football','Baloncesto','Atletismo','Balonmano','Gym','Karate'];
  45.  
  46.  
  47.  
  48.  
  49.  
  50. /* Variable que guarda el valor que se almacenara en la Base de Datos */
  51.  
  52. var checkboxActivados = 0;
  53.  
  54.  
  55.  
  56. function activarValor (numero) {
  57.  
  58.     checkboxActivados ^= numero;
  59.  
  60.  
  61.  
  62. }
  63.  
  64.     
  65.  
  66.  
  67.  
  68. function potencia ( exponente ) {
  69.  
  70. /* Retorna dos elevando al exponente recibido como parametro */
  71.  
  72.  
  73.  
  74.     calculo = 1;
  75.  
  76.     for (x=0;x<exponente;x++) {
  77.  
  78.         calculo = calculo*2;
  79.  
  80.     }
  81.  
  82.  
  83.  
  84.     return calculo;
  85.  
  86. }
  87.  
  88.  
  89.  
  90. function listarActivos() {
  91.  
  92. /* Lista los checkbox que hay activados atendiendo a la variable activado. */
  93.  
  94.  
  95.  
  96.     lista = "Opciones activadas \n";
  97.  
  98.  
  99.  
  100.     for (x=0; x<datos.length; x++) {
  101.  
  102.         activado = checkboxActivados & potencia(x);
  103.  
  104.         if (activado != 0) {
  105.  
  106.             lista = lista +  " ╖" + datos[x] + "\n";
  107.  
  108.         }
  109.  
  110.     }
  111.  
  112.     alert(lista);
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. function escribirOpciones () {
  121.  
  122. /* Funci≤n que crea los checkbox a partir del array */
  123.  
  124.  
  125.  
  126.     for (x=0; x<datos.length; x++) {
  127.  
  128.         document.write("<input type='checkbox' onClick='activarValor(" + potencia(x) + ");'>" + datos[x] + "<br>");
  129.  
  130.     }
  131.  
  132. }
  133.  
  134.  
  135.  
  136. </script>
  137.  
  138.  
  139.  
  140. <form name="form2">
  141.  
  142.   <p> 
  143.  
  144.     <script>escribirOpciones();</script>
  145.  
  146.     <input type="button" name="Button1" value="Check the Data" onClick="alert(checkboxActivados);">
  147.  
  148.     <input type="button" name="Button2" value="CheckBox Selections" onClick="listarActivos();">
  149.  
  150.   </p>
  151.  
  152. </form>
  153.  
  154.  
  155.  
  156.       
  157.  
  158.                 </td>
  159.  
  160.               </tr>
  161.  
  162.             </table>
  163.  
  164.  
  165. <!-- END OF SCRIPT -->
  166. <!/SCRIPT>
  167.  
  168. <!PREVIEW>
  169. <!-- START OF SCRIPT -->
  170.  
  171. <!-- HOW TO INSTALL BINARY OPERATORS AND CHECKBOX:
  172.  
  173.  
  174.  
  175.   1.  Copy code into the body section of document  -->
  176.  
  177.  
  178.  
  179. <!-- STEP ONE: Add this code into BODY section of document  -->
  180.  
  181.  
  182.  
  183. <BODY>
  184.  
  185.  
  186. <!-- Original:  Victor Cuervo (victor@aulambra.com ) -->
  187.  
  188. <!-- Web Site:  http://www.aulambra.com -->
  189.  
  190.             <table border="1" width="100%" cellpadding="10" cellspacing="0" bordercolor="#000000" bordercolordark="#000000" bordercolorlight="#000000" height="339">
  191.  
  192.               <tr>
  193.  
  194.                 <td width="100%" height="297" valign="top"> 
  195.  
  196.                   
  197.  
  198. <script>
  199.  
  200.  
  201.  
  202. datos = ['Football','Baloncesto','Atletismo','Balonmano','Gym','Karate'];
  203.  
  204.  
  205.  
  206.  
  207.  
  208. /* Variable que guarda el valor que se almacenara en la Base de Datos */
  209.  
  210. var checkboxActivados = 0;
  211.  
  212.  
  213.  
  214. function activarValor (numero) {
  215.  
  216.     checkboxActivados ^= numero;
  217.  
  218.  
  219.  
  220. }
  221.  
  222.     
  223.  
  224.  
  225.  
  226. function potencia ( exponente ) {
  227.  
  228. /* Retorna dos elevando al exponente recibido como parametro */
  229.  
  230.  
  231.  
  232.     calculo = 1;
  233.  
  234.     for (x=0;x<exponente;x++) {
  235.  
  236.         calculo = calculo*2;
  237.  
  238.     }
  239.  
  240.  
  241.  
  242.     return calculo;
  243.  
  244. }
  245.  
  246.  
  247.  
  248. function listarActivos() {
  249.  
  250. /* Lista los checkbox que hay activados atendiendo a la variable activado. */
  251.  
  252.  
  253.  
  254.     lista = "Opciones activadas \n";
  255.  
  256.  
  257.  
  258.     for (x=0; x<datos.length; x++) {
  259.  
  260.         activado = checkboxActivados & potencia(x);
  261.  
  262.         if (activado != 0) {
  263.  
  264.             lista = lista +  " ╖" + datos[x] + "\n";
  265.  
  266.         }
  267.  
  268.     }
  269.  
  270.     alert(lista);
  271.  
  272. }
  273.  
  274.  
  275.  
  276.  
  277.  
  278. function escribirOpciones () {
  279.  
  280. /* Funci≤n que crea los checkbox a partir del array */
  281.  
  282.  
  283.  
  284.     for (x=0; x<datos.length; x++) {
  285.  
  286.         document.write("<input type='checkbox' onClick='activarValor(" + potencia(x) + ");'>" + datos[x] + "<br>");
  287.  
  288.     }
  289.  
  290. }
  291.  
  292.  
  293.  
  294. </script>
  295.  
  296.  
  297.  
  298. <form name="form2">
  299.  
  300.   <p> 
  301.  
  302.     <script>escribirOpciones();</script>
  303.  
  304.     <input type="button" name="Button1" value="Check the Data" onClick="alert(checkboxActivados);">
  305.  
  306.     <input type="button" name="Button2" value="CheckBox Selections" onClick="listarActivos();">
  307.  
  308.   </p>
  309.  
  310. </form>
  311.  
  312.  
  313.  
  314.       
  315.  
  316.                 </td>
  317.  
  318.               </tr>
  319.  
  320.             </table>
  321.  
  322.  
  323.  
  324. <!-- END OF SCRIPT -->
  325. <!/PREVIEW>
  326.  
  327. <!RELATED>NONE<!/RELATED>
  328.